package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.OrdersMapper;
import com.ming.easyDevelop.entity.po.Orders;
import com.ming.easyDevelop.entity.query.OrdersQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.OrdersService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import java.util.Date;
import java.math.BigDecimal;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("ordersService")
public class OrdersServiceImpl implements OrdersService {
	private final OrdersMapper<Orders, OrdersQuery> ordersMapper;

	public OrdersServiceImpl(OrdersMapper ordersMapper){
		this.ordersMapper = ordersMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Orders> findListByParam(OrdersQuery query){
		return this.ordersMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(OrdersQuery query){
		return this.ordersMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Orders> findListByPage(OrdersQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Orders> res = this.findListByParam(query);
		return new PaginationResVo<Orders>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Orders> list){
		return this.ordersMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Orders bean){
		return this.ordersMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Orders bean){
		return this.ordersMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Orders> list){
		return this.ordersMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据OrderID查询
	 */
	@Override
	public Orders getByOrderID(Integer orderID){
		return this.ordersMapper.selectByOrderID(orderID);
	}

	/**
	 * 根据OrderID更新
	 */
	@Override
	public Long updateByOrderID(Orders bean, Integer orderID){
		return this.ordersMapper.updateByOrderID(bean,orderID);
	}

	/**
	 * 根据OrderID删除
	 */
	@Override
	public Long deleteByOrderID(Integer orderID){
		return this.ordersMapper.deleteByOrderID(orderID);
	}

}
